package com.flow.asyncflow.core.utils.common;


import com.flow.asyncflow.core.annotation.NodeInfo;
import com.flow.asyncflow.core.entity.log.asyncflowlog.AsyncFlowExecutionMethodEntity;
import com.flow.asyncflow.core.enums.NodeTypeEnum;

import java.lang.annotation.Annotation;

public class UtilsCommon {
    /**
     * 获取方法执行名称
     *
     * @param obj 执行的方法的对象
     * @return 执行方法信息
     */
    public static AsyncFlowExecutionMethodEntity getLogMethodName(Object obj) {
        Class<?> clazz = obj.getClass();
        String logMethodName = null;
        Annotation[] logMethods = clazz.getAnnotations();
        for (Annotation annotation : logMethods) {
            //获取方法名
            if (annotation instanceof NodeInfo) {
                logMethodName = ((NodeInfo) annotation).name();
                if (((NodeInfo) annotation).nodeType() == NodeTypeEnum.OldPubNode) {
                    logMethodName = logMethodName + "【公共节点】";
                }
                break;
            }
        }
        AsyncFlowExecutionMethodEntity asyncFlowExecutionMethodEntity = new AsyncFlowExecutionMethodEntity();
        asyncFlowExecutionMethodEntity.setLogMethodName(logMethodName);
        asyncFlowExecutionMethodEntity.setMethodSimpleName(clazz.getSimpleName());
        asyncFlowExecutionMethodEntity.setMethodName(clazz.getName());
        return asyncFlowExecutionMethodEntity;
    }


}
